package com.nc.solutions.rentacar.manager.Impl;

import com.nc.solutions.rentacar.domain.car.ICar;
import com.nc.solutions.rentacar.domain.car.Impl.Car;
import com.nc.solutions.rentacar.manager.ICarManager;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author Alex Avdeychik
 */
public class CarManager implements ICarManager {

	private Map<Integer, ICar> carMap;

	public CarManager() {
		carMap = new TreeMap<Integer, ICar>();
	}

	@Override
	public Map<Integer, ICar> getCarMap() {
		return new TreeMap(carMap);
	}

	@Override
	public void addCar(ICar car) {
		carMap.put((int) car.getID(), car);
	}

	@Override
	public boolean removeCar(int carId) {
		return carMap.remove(carId) != null;
	}

	@Override
	public ICar getCar(int carId) {
		return carMap.get(carId);
	}

	public void test() {
		Car c1 = new Car();
		c1.setID(1);
		c1.setNumber("number1");
		Car c2 = new Car();
		c2.setNumber("number2");
		c2.setID(2);
		Car c3 = new Car();
		c3.setNumber("number3");
		c3.setID(3);
		this.addCar(c1);
		this.addCar(c2);
		this.addCar(c3);
	}
}
